package com.andy.mvp.poetry.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.andy.mvp.R;
import com.andy.mvp.poetry.bean.Proetry;

import java.util.ArrayList;

/**
 * @version V1.0
 * @描述:
 * @Company:
 * @auth: Created by AN .
 * @time: 2020/3/27 18:22
 * @des
 */
public class PoetryAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private ArrayList<Proetry> proetries;

    public PoetryAdapter(Context context, ArrayList<Proetry> proetries) {
        inflater = LayoutInflater.from(context);
        this.proetries = proetries;
    }

    @Override
    public int getCount() {
        return proetries.size();
    }

    @Override
    public Object getItem(int position) {
        return proetries.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public  void setData(ArrayList<Proetry> proetries){
        this.proetries = proetries;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder  holder=null;
        if(convertView == null){
            convertView=inflater.inflate(R.layout.item_proetry, null);
            holder = new ViewHolder();
            holder. tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder. tv_auoth = (TextView) convertView.findViewById(R.id.tv_auoth);
            holder. tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        Proetry proetry = proetries.get(position);
        holder.tv_title.setText("" + proetry.getTitle());
        holder.tv_auoth.setText("" + proetry.getAuoth());
        holder.tv_content.setText("" + proetry.getContent());


        return convertView;
    }

    public static class ViewHolder {
        public TextView tv_title;
        public TextView tv_auoth;
        public TextView tv_content;
    }
}

